﻿using CodeCity.AutomationMachine.DomainModels;
using NRules.Fluent.Dsl;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CodeCity.AutomationMachine.Rules
{
    public class EnvironmentRule : Rule
    {
        public override void Define()
        {
            SkyEnvironment skyEnvironment = null;
            When()
                .Match(() => skyEnvironment);

            Then()
                .Do(context => ChangeEnvironment(skyEnvironment));
        }

        void ChangeEnvironment(SkyEnvironment skyEnvironment)
        {
            skyEnvironment.Now = skyEnvironment.Now.AddMilliseconds(100);
            var now = skyEnvironment.Now;
            var zero = new DateTime(now.Year, now.Month, now.Day);
            if (now.Hour >= 0 && now.Hour < 12)
            {
                skyEnvironment.Temperature += 0.000462962962;//最终变到30度，总共变化20度
            }
            else
            {
                skyEnvironment.Temperature -= 0.000462962962;//最终变到10度，总共变化20度
            }
            Log.Logger.Information($"【{{Rule}}】世界时间：{now}，温度：{skyEnvironment.Temperature}", "ENV");
        }
    }
}
